/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package chelydra.sharelydra.client.misc;

import chelydra.sharelydra.client.network.DownloadFileThread;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;

/**
 *
 * @author Benjamin
 */
public class IniLoader {

        /**
         * This methods get the content from a ini file :
         * Exemple of Ini file:
         * _______________________________
         * DefaultSharedFolder=/toto/tata/papoum
         * Database Path=./../dbpath
         * _______________________________
         *
         *
         */public static void loadIniFile(){
        try{
            File file = new File("config.ini.txt");
            FileReader fr= new FileReader(file);
            BufferedReader br = new BufferedReader(fr);
            String text= "";
            String tempText = "";
            System.out.println("Loading Config.ini.txt file");
            while( (tempText = br.readLine() ) !=null){
                text = text + tempText +"#";
            }
            System.out.println("Loading Config.ini.txt file done: Now parsing it");
            String[] line= null;
            line = text.split("#");
            String part;
            int i=0;
            while(i < line.length ){
                IniLoader.processLine(line[i]);
                i++;
            }
            System.out.println("Data extracted from conf.ini.txt:");

        }catch (Exception e){
            System.out.println("Problemes loading config.ini");
        }
    }

    private static void processLine(String string) {
        String[] part;
        part = string.split("=");
        //check if the first part of the line is equal to a know default Value
        if( part[0].equalsIgnoreCase("DefaultSharedFolder")){
            DefaultValue.DefaultSharedFolder=part[1];
            
        }
    }

}
